// pages/search/index.js
import { request } from '../../request/index'
import regeneratorRuntime from '../../lib/runtime/runtime';
Page({

  /**
   * 页面的初始数据 
   */
  data: {
    goods: [],
    isfocus: false,
    value: ''
  },
  TimeId: -1,
  handleChange (e) {
    const { value } = e.detail;
    if (!value.trim()) {
      // 输入的值不合法
      this.setData({
        goods: [],
        isfocus: false
      })
      return;
    }
    this.setData({
      isfocus: true
    })
    clearTimeout(this.TimeId)
    this.TimeId = setTimeout(() => {
      this.qsearch(value);
    }, 1000);
  },
  Cancle () {
    this.setData({
      goods: [],
      isfocus: false,
      value: ""
    })
  },
  async qsearch (query) {
    const res = await request({ url: "/goods/qsearch", data: { query } })
    console.log(res)
    this.setData({
      goods: res
    })
  },
  onShow: function () {

  },
})